<?php
/* $Id: orderlist.php 47 2011-02-20 17:26:53Z jim2212001@gmail.com $ */
require_once 'config.php';

define(PERPAGE,30);
/* Parse school and department*/
$where = '';
if($_GET['school']>0)
	$where .='`schoolId` = \''.intval($_GET['school']).'\'';
if($_GET['dept']>0)
	$where .='`departmentId` = \''.intval($_GET['dept']).'\'';
if(strlen($where))
	$where = 'WHERE '.$where;

/* Parse page */
$offset=$_GET['page']>0?intval($_GET['page'])*PERPAGE:-1;
$limit = ($offset+1).','.PERPAGE;

$sql='SELECT orderlist.*,
  orderlist.id AS oid,
  orderlist.title AS oname,
  account.name AS founder
FROM `orderlist` LEFT JOIN `account` ON founderId = account.id '.$where.' ORDER BY orderlist.id DESC LIMIT '.$limit;
$res = $db->query($sql,1);

/*$list = array(
			  'id'=>'ID',
			  'name'=>'專案名稱',
			  'info'=>'專案敘述',
			  'startTime'=>'開始時間',
			  'endTime'=>'結束時間',
			  'founder'=>'發起人'
			  );*/
$list = array();
while($row = $res->fetch_assoc()){
	array_push($list,array(
		'id'=>$row['oid'],
		'name'=>$row['oname'],
		'info'=>$row['info'],
		'startTime'=>$row['startTime'],
		'closedTime'=>$row['closedTime'],
		'founder'=>$row['founder']
	));
}
$res->close();

$tpl->assign('subtitle','檢視訂單');
$tpl->assign('list',$list);
$tpl->display('orderlist.htm');
?>
